-
Notifications
You must be signed in to change notification settings - Fork 38.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
only output "No resources found." for human readable printers #40551
only output "No resources found." for human readable printers #40551
Conversation
Hi @juanvallejo. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
@k8s-bot ok to test |
Add a test for this behavior to test-cmd |
@kubernetes/sig-cli-pr-reviews |
local message=$1 | ||
local match=$2 | ||
|
||
if [[ $(echo "$message" | grep "$match") ]]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if ! grep -q "${match}" <<<"${message}"; then
# message does not contain match
fi
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although I trust your bash knowledge, somehow the original solution seems more readable to me bash scripting ignorant ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original solution is bad for a large number of reasons. The command-line output of grep
is not necessarily stable. if grep
finds nothing on your system and in 2017, it doesn't output anything. Tomorrow, someone pushes a change that says "No matches found" (sound familiar? :) ) and suddenly the original check breaks.
The bash if
statement is meant to check for return codes of commands (for example, in the original implementation it is checking for the return code of the [[
command). grep
, being a well-formed program, will always return 0
if and only if it succeeded, and will return non-zero otherwise. It is always better to use if program
rather than spawning a subshell, capturing the output, relying on the hidden default behavior of [[
with strings (that is different with [
, by the way)...
LGTM, please squash. |
eb24f9d
to
7b808ad
Compare
local message=$1 | ||
local match=$2 | ||
|
||
if echo "$message" | grep "$match" 2>&1>/dev/null; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
grep -q
not redirect
7b808ad
to
5ec2a4c
Compare
@juanvallejo: The following test(s) failed:
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
Thanks, done! |
/lgtm |
/approve |
1 similar comment
/approve |
[APPROVALNOTIFIER] This PR is APPROVED The following people have approved this PR: eparis, fabianofranz Needs approval from an approver in each of these OWNERS Files:
You can indicate your approval by writing |
Automatic merge from submit-queue (batch tested with PRs 40691, 40551, 40683, 40700, 40702) |
Release note:
This patch removes the message
No resources found
(currently printed through stderr) when printing through a generic / non-human-readable printer (json, yaml, jsonpath, custom-columns).Before*
After
cc @fabianofranz @stevekuznetsov